#include<stdio.h>

void ftoa(double f, char s[])
{
    int n; //存放整数
    double m; //存放小数
    int len = 0; //赋值
    int flag = 0;
    if(f < 0) 
    {
        f = -f;
        flag = 1;
    }
    n = (int)f;
    m = f - n;
    do
    {
        s[len++] = (n % 10) + '0';
        n/=10;
    } while (n);

    for(int i = len - 1,j = 0; j < len/2; j++)
    {
        char t = s[j];
        s[j] = s[i-j];
        s[i-j] = t;
    }
    s[len++] = '.';
    while((int)(m*10))
    {
        s[len++] = (int)(m*10) + '0';
        m = m*10 - (int)(m*10);
    }
    s[len] = '\0';
    if(flag == 1)
    {
        printf("-");
    }
    printf("%s",s);
    
}
int main()
{
    freopen("in.txt","r",stdin);
    double f = -332.1415;
    char s[20];
    ftoa(f,s);
}
